﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Linq.Expressions;
using Small.Html.Entities;

namespace Small.Html.Common
{
   public class HtmlModelHelper
    {

       /// <summary>
       /// 获取到实体类中的名称和名称
       /// </summary>
       /// <typeparam name="TModel"></typeparam>
       /// <typeparam name="TProperty"></typeparam>
       /// <param name="helper"></param>
       /// <param name="expression"></param>
       /// <returns></returns>
       public static HtmlModelItem GetProperties<TModel, TProperty>(HtmlHelper<TModel> helper,Expression<Func<TModel, TProperty>> expression) 
       {
           HtmlModelItem item=new HtmlModelItem();
              item.Name = ExpressionHelper.GetExpressionText(expression);
              item.Value = ModelMetadata.FromLambdaExpression<TModel, TProperty>(expression, helper.ViewData).Model;
              return item;
       }
    }
}
